package com.EAsystem.entity;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;

public class Leave {
    private Integer id;
    private Student student;
    private Course course;
    private String reason;
    private String startTime;
    private String endTime;
    private Integer status;
    private String createTime;
    private String updateTime;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Student getStudent() {
        return student;
    }

    public void setStudent(Student student) {
        this.student = student;
    }

    public Course getCourse() {
        return course;
    }

    public void setCourse(Course course) {
        this.course = course;
    }

    public String getReason() {
        return reason;
    }

    public void setReason(String reason) {
        this.reason = reason;
    }

    public String getStartTime() {
        return startTime;
    }

    public void setStartTime(String startTime) {
        this.startTime = startTime;
    }

    public String getEndTime() {
        return endTime;
    }

    public void setEndTime(String endTime) {
        this.endTime = endTime;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public String getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(String updateTime) {
        this.updateTime = updateTime;
    }
    
    /**
     * 计算请假天数
     * @return 请假天数
     */
    public long getLeaveDays() {
        if (startTime == null || endTime == null) {
            return 0;
        }
        try {
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            LocalDate start = LocalDate.parse(startTime.substring(0, 10), formatter);
            LocalDate end = LocalDate.parse(endTime.substring(0, 10), formatter);
            return ChronoUnit.DAYS.between(start, end) + 1;
        } catch (Exception e) {
            return 0;
        }
    }
    
    /**
     * 获取审核状态描述
     * @return 状态描述
     */
    public String getStatusText() {
        if (status == null) {
            return "待审核";
        }
        switch (status) {
            case 0: return "待审核";
            case 1: return "审核通过";
            case 2: return "审核不通过";
            default: return "未知状态";
        }
    }
}
